<template>
  <div class="view-container">

    <table-search-view ref="orderView" :search-items="searchItems" :table-items="tableItems" :search-function="search">
      <template slot="action" slot-scope="scope">
        <action-returned :scope="scope" @returned-success="returnedSuccess"></action-returned>
        <action-unreceived :scope="scope" @unreceived-success="unreceivedSuccess"></action-unreceived>
        <action-info :scope="scope"></action-info>
      </template>
    </table-search-view>

  </div>
</template>

<script>
  import TableSearchView from '@/components/TableSearchView';

  import actionOrderInfo from './components/actionOrderInfo.vue';
  import actionReturned from './components/actionReturned.vue';
  import actionUnreceived from './components/actionUnreceived.vue';

  import {getOrderReturnedList} from '@/api/order';

  export default {
    name: 'orderReturned', /*已退还*/
    components: {
      'table-search-view':TableSearchView,
      'action-info':actionOrderInfo,
      'action-returned':actionReturned,
      'action-unreceived':actionUnreceived,

    },
    data ()
    {
      return {
        searchItems: [
          {
            label: '商品名称',
            type: 'autocomplete',
            placeholder:'请输入商品名称',
            model:'goodName',
          },
          {
            label: '收货时间',
            type: 'datetimerange',
            placeholder:'请选择收货时间',
            model:'timeRange',
          },
          {
            label: '订单编号',
            type: 'input',
            placeholder:'请输入订单编号',
            model:'orderId',
          },
          {
            label: '下单用户',
            type: 'input',
            placeholder:'请输入下单用户',
            model:'userName',
          }
        ],
        tableItems:[
          {
            label:'订单编号',
            prop:'orderNumber',
            width:'180px;',
          },
          {
            label:'商品名称',
            prop:'goodsName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'下单用户',
            prop:'userName',
            width:'180px;',
            sortable:true,
          },
          {
            label:'退还方式',
            prop:'mode',
            width:'120px;',
            sortable:true,
          },
          {
            label:'收货时间',
            prop:'receivedTime',
            width:'160px;',
            formatter:'parseTime',
          },
          {
            label:'订单状态',
            prop:'stateStr',
            width:'120px;',
            sortable:true,
          },
          {
            type:'scope',
            label:'操作',
            slot:'action',
            width:'220px;',
          },
          {

          }
        ],
      }
    },
    methods: {
      search(data)
      {
        return getOrderReturnedList(data);
        /*return new Promise(resolve => {
          let resp = {data:{total:10, list:[
            {
              "id": 77502,
              "goodsName": "fXxhjled8Q",
              "userName": "dfOO13vlVj",
              "mode": "快递",
              "receivedTime": 1505973004354,
              "state": "returned",
              "stateStr": "已退还"
            },
            {
              "id": 78043,
              "goodsName": "GrpOxAO62z",
              "userName": "NAPe2v1uLA",
              "mode": "快递",
              "receivedTime": 1505972760413,
              "state": "returned_unreceived",
              "stateStr": "平台处理中"
            }
          ]}};

          resolve(resp);
        });*/
      },
      unreceivedSuccess()
      {
        this.$refs['orderView'].search();
      },
      returnedSuccess()
      {
        this.$refs['orderView'].search();
      }
    }
  }
</script>
